﻿<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>前锋图书管理系统</title>
    <link rel="stylesheet" href="/css/public.css"/>
    <link rel="stylesheet" href="/css/style.css"/>
    <link rel="stylesheet" href="/js/layui/css/layui.css"  media="all">
</head>
<style>
    html,body{
        width: 100%;
        height: 100%;
    }
    .homeWrap{
        width: 100%;height: 100%;
        padding-top: 76px;position: relative;box-sizing: border-box;overflow: hidden;
    }
    .homeWrap div{box-sizing: border-box;}
    .hide{
        display: none;
    }
    .detelebox button{
        width: 50px;
        height: 28px;
        margin-top: 10px;
        margin-left: 50px;
        display: inline-block;
        border: 1px solid #679e43;
        background: linear-gradient(to bottom,#baf076,#a2d866,#9cd055,#8dc838,#8bc93a);
        line-height: 28px;
        text-align: center;
        border-radius: 4px;
        font-weight: bold;
        color: #fff;
    }
    .publicMian,.left{height: 100%;}
    .homeHeader{width: 100%; position: absolute;left: 0;top: 0;}
</style>
<body>
<div class="homeWrap">
    <div class="homeHeader">
            <!--头部-->
        <header class="publicHeader">
            <h1>前锋图书管理系统</h1>
            <div class="publicHeaderR">
                <p><span>下午好！</span><span style="color: #fff21b"> Admin</span> , 欢迎你！</p>
                <a href="/admin/index/signOut">退出</a>
            </div>
        </header>
    <!--时间-->
        <section class="publicTime">
            <span id="time">2015年1月1日 11:11  星期一</span>
        </section>
    </div>

<!--主体内容-->
    <section class="publicMian">
        <div class="left">
            <h2 class="leftH2"><span class="span1"></span>功能列表 <span></span></h2>
            <nav>
                <ul class="list">
                    <li id="active"><a href="/admin/home/home">首页</a></li>
                    <li><a href="/admin/home/borrowingmanagement">借阅管理</a></li>
                    <li><a href="/admin/home/bookrecord">图书记录</a></li>
                    <li><a href="/admin/home/bookadd">图书添加</a></li>
                    <li><a href="/admin/scrollmember/scroll">滚屏</a></li>
                    <li><a href="/admin/scrollmember/member">会员管理</a></li>
                    <li><a href="/admin/home/editpass">修改密码</a></li>
                    <li><a href="/admin/home/groupbuy">团队来源</a></li>
                </ul>
            </nav>
        </div>
        <div class="right">
            <div class="location">
                <strong>你现在所在的位置是:</strong>
                <span>首页</span>
            </div>
            <div class="search">
                <span>搜索：</span>
                <input type="text" placeholder="请输入用户名/书名" id="content"/>
                <input type="button" value="查询" id="search"/>
                <span>图书总数：{$sum | default=''}</span>
            </div>
            <!--账单表格 样式和供应商公用-->
            <div class="record">

            </div>
            <div class="pagePage" style="top: 800px;">
                <div class="page_control">
                    <div class="pagination"></div>
                </div>
            </div>
        </div>

    </section>
</div>

<script src="/js/jquery.js"></script>
<script src="/js/js.js"></script>
<script src="/js/time.js"></script>
<script src="/js/layui/layui.js"></script>
<script src="/js/jquery.paging.js"></script>
<script>
    // 弹出删除点击确定
    function deleteOk(id){
        var reason = $("#delete").val();
        if(reason == ''){
            layer.msg('请填写删除原因');
        }
        else{
            $.ajax({
                url:'/admin/home/deleteBook',
                type:'POST',
                data:{
                    id:id,
                    reason:reason
                },
                success:function(res){
                    if(res == 1){
                        layer.msg('删除成功');
                        $('.detelebox').addClass('hide');
                        window.location.href='/admin/home/home';
                    }
                    else{
                        layer.msg('删除失败');
                        $('.detelebox').addClass('hide');
                    }
                },
                error:function(){

                }
            });
        }
    }
    // 修改图书
    function editBook(id){
        var img = $('#demo1').attr('src');
        var bookName = $("#money").val();
        var bookFrom = $("#bookFrom").val();
        if(imgUrl == ''){
            imgUrl = img;
        }
        if(bookName == ''){
            layer.msg('请填写图书名称');
        }
        else if(bookFrom == ''){
            layer.msg('请选择图书来源');
        }
        else{
            $.ajax({
                url:'/admin/home/bookEdit',
                type:'POST',
                data:{
                    id:id,
                    imgUrl:imgUrl,
                    bookName:bookName,
                    bookFrom:bookFrom
                },
                success:function(res){
                    if(res == 1){
                        layer.msg('编辑成功');
                        $('.providerAdd').addClass('hide');
                        window.location.href='/admin/home/home';
                    }
                    else if(res == 2){
                        layer.msg('这本书已经存在');
                    }
                    else{
                        layer.msg('编辑失败');
                        $('.providerAdd').addClass('hide');
                    }
                },
                error:function(){

                }
            });
        }

    }
</script>
<script>
    // 分页
    $('.pagination').paging({
        total: '',
        currentPage: '',
        showPage: 5,        //显示的页数
        animation: false,
        showJump: false,
        ajaxSubmitType: 'post',
        simpleType: 1,
        url: '/admin/home/pageHomeList',
        idParameter: "page",
        ajaxData: {'pageSize': 1},
        beforeAjaxSubmit: function () {
            PageAPI.AddAjaxData({"pageSize": $(".pageSize").val()});
        },
        ajaxSubmitBack: function (data) {
            console.log(data);
            $('.record').empty();
            var orderinfo = data.data;
            if(orderinfo=='' ||orderinfo==undefined){
                $(".record").html(' <h2 style="text-align: center;padding-top:120px;height: 166px;color: red;">暂无数据</h2>');
                $(".pagination").hide();
            }else{
                $(".pagination").show();
                var infohtml="";
                infohtml += '<table class="providerTable" cellpadding="0" cellspacing="0">'
                infohtml += '<tr class="firstTr">'
                infohtml += '<th width="10%">图片</th>'
                infohtml += '<th width="10%">书名</th>'
                infohtml += '<th width="10%">借阅人</th>'
                infohtml += '<th width="10%">借阅时间</th>'
                infohtml += '<th width="10%">逾期时间</th>'
                infohtml += '<th width="10%">状态</th>'
                infohtml += '<th width="10%">图书来源</th>'
                infohtml += '<th width="10%">操作</th>'
                infohtml += '</tr>'
                $.each(orderinfo,function(index,value){
                    infohtml += '<tr>'
                    infohtml += '<td class="tdclass">'
                    infohtml += '<img src="'+value['img']+'" class="imgclass"/>'
                    infohtml += '</td>'
                    infohtml += '<td>'+value['bname']+'</td>'
                    if(value['name']){
                        infohtml += '<td>'+value['name']+'</td>'
                    }
                    else{
                        infohtml += '<td>---</td>'
                    }
                    if(value['booktime']){
                        infohtml += '<td>'+unix_to_datetime(value['booktime'])+'</td>'
                    }
                    else{
                        infohtml += '<td>---</td>'
                    }

                    if(value['isBeOverdue']){
                        infohtml += '<td>'+value['isBeOverdue']+'</td>'
                    }else{
                        infohtml += '<td>---</td>'
                    }
                    if(value['bstates']==1){
                        infohtml += '<td>未借出</td>'
                    }
                    else{
                        infohtml += '<td>已借出</td>'
                    }
                    infohtml += '<td>'+value['from']+'</td>'
                    infohtml += '<td>'
                    if(value['bid']){
                        infohtml += '<input type="button" onclick="editBooksInsi('+value['bid']+')" value="编辑" class="anniu"/>';
                        infohtml += '<input type="button" onclick="deleteRecord('+value['bid']+')" value="删除" class="anniu"/>';
                    }
                    else{
                        infohtml += '<input type="button" onclick="editBooksInsi('+value['id']+')" value="编辑" class="anniu"/>';
                        infohtml += '<input type="button" onclick="deleteRecord('+value['id']+')" value="删除" class="anniu"/>';
                    }
                    infohtml += '</td>'
                    infohtml += '</tr>'
                });
                infohtml += '</table>';
                $(".record").html(infohtml)
            }
        },
        ajaxFormatBack: function (data) {
            data.total = data.totalpage;
            data.currentPage = data.currentPage;
        }
    });
    // 时间戳转换成日期
    function unix_to_datetime(unix) {
        var now = new Date(parseInt(unix) * 1000);
        return now.toLocaleString().replace(/年|月/g, "-").replace(/日/g, " ");
    }
    // 编辑图书
    var bookid;
    var imgUrl = '';   // 图片地址
    function editBooksInsi(id){
        $.ajax({
            url:'/admin/home/selectBook',
            type:'POST',
            data:{id:id},
            success:function(res){
                console.log(res);
                layui.use('upload', function(){
                    var $ = layui.jquery
                        ,upload = layui.upload;
                    layer.open({
                        type: 1,
                        title:'请编辑图书信息',
                        area: ['813px','604px','-116.5px','334.5px'],
                        shadeClose: true, //点击遮罩关闭
                        content:'<div class="providerAdd" style="width: 90%;">' +
                        '<div style="width: 270px;height: 300px;border: 1px solid grey;margin-left: 204px;">' +
                        '<label for="billNum" style="margin-left:-200px;">图片：</label>' +
                        '<div>' +
                        '<div class="layui-upload">' +
                        '<div class="layui-upload-list">' +
                        '<img class="layui-upload-img" id="demo1" style="width: 100%;margin-top: -30px;height: 200px;" src="'+res[0]['img']+'">' +
                        '<p id="demoText"></p>' +
                        '</div>' +
                        '<button type="button" class="layui-btn" id="test1" style="margin-left: 80px;">上传图片</button>' +
                        '</div>' +
                        '</div>' +
                        '<span style="position: relative;left: 271px;">*图书封面</span>' +
                        '</div>' +
                        '<div>' +
                        '<label for="money">书名：</label>' +
                        '<input type="text" name="money" id="money" value="'+res[0]['bname']+'" required/>' +
                        '<span>*请填写图书名称</span>' +
                        '</div>' +
                        '<div>' +
                        '<label >图书来源：</label>' +
                        '<input type="text" name="money" id="bookFrom" value="'+res[0]['from']+'" required/>' +
                        '<span>*请填写图书供应商</span>' +
                        '</div>' +
                        '<div class="providerAddBtn">' +
                        '<input type="button" value="确认更改" onclick="editBook('+id+')" style="width: 274px;margin-left: -40px;"/>' +
                        '</div>' +
                        '</div>'
                    });
                    //普通图片上传
                    var uploadInst = upload.render({
                        elem: '#test1'
                        ,url: '/admin/UploadImg/uploadImg'
                        ,before: function(obj){
                            //预读本地文件示例，不支持ie8
                            obj.preview(function(index, file, result){
                                $('#demo1').attr('src', result); //图片链接（base64）
                            });
                        }
                        ,done: function(res){
                            console.log(res)
                            //如果上传成功
                            if(res.code == 1){
                                imgUrl = res.photo;
                            }
                            else{
                                return layer.msg('上传失败');
                            }
                        }
                        ,error: function(){
                            //演示失败状态，并实现重传
                            var demoText = $('#demoText');
                            demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
                            demoText.find('.demo-reload').on('click', function(){
                                uploadInst.upload();
                            });
                        }
                });

            });
            }
        });
            bookid = id;
        // $('.providerAdd').removeClass('hide');
    }
    // 删除记录
    function deleteRecord(id){
        layui.use('upload', function() {
            layer.open({
                type: 1,
                title: '请填写删除信息',
                area: ['300px', '170px', '-116.5px', '334.5px'],
                shadeClose: true, //点击遮罩关闭
                content:
                '<div class="layui-card-body">' +
                '<input type="text" id="delete" placeholder="请输入删除原因" style="width: 100%;height: 40px;"/>' +
                '<input type="button" onclick="deleteOk(' + id + ')" value="确定" class="anniu" style="width: 70px;margin-left: 100px;margin-top: 20px;"/>' +
                '</div>'
            });
        })
    }
</script>
<script>
    $('#search').click(function(){
        var name = $('#content').val();
        if(name!=''){
            ajaxSearch(name,4);
        }
    })
    // 搜索添加
    function ajaxSearch(name){
        $(".pagination").empty();
        $('.pagination').paging({
            total: '',
            currentPage: '',
            showPage: 5,        //显示的页数
            animation: false,
            showJump: false,
            ajaxSubmitType: 'post',
            simpleType: 1,
            url: '/admin/index/search',
            idParameter: "page",
            ajaxData: {'pageSize': 1,name:name,type:4},
            beforeAjaxSubmit: function () {
                PageAPI.AddAjaxData({"pageSize": $(".pageSize").val()});
            },
            ajaxSubmitBack: function (data) {
                console.log(data);
                $('.record').empty();
                var orderinfo = data.data;
                if(orderinfo=='' ||orderinfo==undefined){
                    $(".record").html(' <h2 style="text-align: center;padding-top:120px;height: 166px;color: red;">暂无数据</h2>');
                    $(".pagination").hide();
                }else{
                    $(".pagination").show();
                    var infohtml="";
                    infohtml += '<table class="providerTable" cellpadding="0" cellspacing="0">'
                    infohtml += '<tr class="firstTr">'
                    infohtml += '<th width="10%">图片</th>'
                    infohtml += '<th width="10%">书名</th>'
                    infohtml += '<th width="10%">借阅人</th>'
                    infohtml += '<th width="10%">借阅时间</th>'
                    infohtml += '<th width="10%">逾期时间</th>'
                    infohtml += '<th width="10%">状态</th>'
                    infohtml += '<th width="10%">图书来源</th>'
                    infohtml += '<th width="10%">操作</th>'
                    infohtml += '</tr>'
                    $.each(orderinfo,function(index,value){
                        infohtml += '<tr>'
                        infohtml += '<td class="tdclass">'
                        infohtml += '<img src="'+value['img']+'" class="imgclass"/>'
                        infohtml += '</td>'
                        infohtml += '<td>'+value['bname']+'</td>'
                        if(value['name']){
                            infohtml += '<td>'+value['name']+'</td>'
                        }
                        else{
                            infohtml += '<td>---</td>'
                        }
                        if(value['booktime']){
                            infohtml += '<td>'+unix_to_datetime(value['booktime'])+'</td>'
                        }
                        else{
                            infohtml += '<td>---</td>'
                        }

                        if(value['isBeOverdue']){
                            infohtml += '<td>'+value['isBeOverdue']+'</td>'
                        }else{
                            infohtml += '<td>---</td>'
                        }
                        if(value['bstates']==1){
                            infohtml += '<td>未借出</td>'
                        }
                        else{
                            infohtml += '<td>已借出</td>'
                        }
                        infohtml += '<td>'+value['from']+'</td>'
                        infohtml += '<td>'
                        if(value['bid']){
                            infohtml += '<input type="button" onclick="editBooksInsi('+value['bid']+')" value="编辑" class="anniu"/>';
                            infohtml += '<input type="button" onclick="deleteRecord('+value['bid']+')" value="删除" class="anniu"/>';
                        }
                        else{
                            infohtml += '<input type="button" onclick="editBooksInsi('+value['id']+')" value="编辑" class="anniu"/>';
                            infohtml += '<input type="button" onclick="deleteRecord('+value['id']+')" value="删除" class="anniu"/>';
                        }
                        infohtml += '</td>'
                        infohtml += '</tr>'
                    });
                    infohtml += '</table>';
                    $(".record").html(infohtml)
                }
            },
            ajaxFormatBack: function (data) {
                data.total = data.totalpage;
                data.currentPage = data.currentPage;
            }
        });
    }

</script>
</body>
</html>